package com.zzedu.system.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzedu.common.cache.CacheNameContansts;
import com.zzedu.common.utils.StringUtils;
import com.zzedu.system.domain.SysRegion;
import com.zzedu.system.mapper.SysRegionMapper;
import com.zzedu.system.service.ISysRegionService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 省市区信息Service业务层处理
 *
 * @author Mr.Wang
 * @date 2023-03-08
 */
@Service
public class SysRegionServiceImpl extends ServiceImpl<SysRegionMapper, SysRegion> implements ISysRegionService {
    public final static String cacheName = CacheNameContansts.SYS_REGION;

    @Override
    @Cacheable(value = cacheName, key = "'region:'+#p0")
    public SysRegion getById(Serializable id) {
        return super.getById(id);
    }

    @Override
    @Cacheable(value = cacheName, key = "#p0+':'+#p1+':'+#p2")
    public List<SysRegion> query(Long regionLevel, String parentId, String regionId) {
        return this.list(Wrappers.lambdaQuery(SysRegion.class)
                .eq(null != regionLevel, SysRegion::getRegionLevel, regionLevel)
                .eq(StringUtils.isNotBlank(parentId), SysRegion::getParentId, parentId).
                eq(StringUtils.isNotBlank(regionId), SysRegion::getRegionId, regionId));
    }

}
